
//
//  RCTabBar.m
//  RC-VVeiboOC
//
//  Created by 任淳 on 16/4/4.
//  Copyright © 2016年 ReverChun. All rights reserved.
//

#import "RCTabBar.h"

@interface RCTabBar ()

@property(nonatomic)UIButton *addBtn;

@end

@implementation RCTabBar

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.barTintColor = [UIColor purpleColor];
        
        self.addBtn = [[UIButton alloc] init];
        [self.addBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [self.addBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        
        [self.addBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [self.addBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        
        [self addSubview:self.addBtn];
        
    }
    
    return self;
}

//重新布置tabBar上按钮的位置
-(void)layoutSubviews {
    
    float btnW = self.frame.size.width / 5;
    
    NSInteger index = 0;
    
    for (NSInteger i = 0; i < self.subviews.count; i++) {
        UIView *sub = self.subviews[i];
        
        if ([sub isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            if (index == 2) {
                //设置addBtn的frame
                self.addBtn.frame = CGRectMake(btnW * index, 1, btnW, self.frame.size.height - 1);
                
                index++;
            }
            
            sub.frame = CGRectMake(btnW * index, 1, btnW, self.frame.size.height - 1);
            
            index++;
        }
        
    }
    
}

@end
